package com.cn.cxq.controller;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cn.cxq.bean.Default;
import com.cn.cxq.bean.User;

@Controller
@RequestMapping("home")
public class DefaultController {
	@Autowired
	Default def;

	@RequestMapping
	public String login(HttpServletRequest request, Model model) throws SQLException {
		User user = def.getuser();
		request.getSession().setAttribute("user", user);
		String html = def.getRoleLi(user.getRole());
		model.addAttribute("menu", html);
		return "home/index";
		
	}
	
	@RequestMapping("/home")
	public String DefaultHome(Model model) throws SQLException {
		return "home/home";
		
	}
	
	@RequestMapping("/json")
	@ResponseBody
	public Object getJson(Model model, User user) throws SQLException {
		Map<String, User> map = new HashMap<String, User>();
		
		map.put("1", user);
		map.put("2", user);
		map.put("3", user);
		return map;
		
	}

}
